<template>
  <div style="padding:20px;" id="app">
    <div class="panel panel-primary">
      <div class="panel-heading">ceshi</div>
      <div class="align-center">
  <el-table
    :data="tableData"
    border
    style="width: 100%">
    <el-table-column
      prop="sourceid"
      label="数据源id">
    </el-table-column>
    <el-table-column
      prop="dbname"
      label="数据db"
      width="180">
    </el-table-column>
      <el-table-column
        prop="tablename"
        label="数据table">
      </el-table-column>
    <el-table-column
      prop="resourcename"
      label="资源名称"
      width="180">
    </el-table-column>
      <el-table-column
        prop="sharetype"
        label="共享类型"
        width="180"
        :formatter="sharetypeformatter">
      </el-table-column>
    <el-table-column
      prop="sharestyle"
      label="共享方式"
      width="180" :formatter="sharestyleformatter">
    </el-table-column>
    <el-table-column
      prop="department"
      label="资源所属部门">
    </el-table-column>
    <el-table-column
      prop="isPublish"
      label="发布状态" :formatter="publishformatter">
    </el-table-column>
    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="applyresource(scope.row)" type="text" size="small">申请</el-button>
        <el-button type="text" size="small">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
</div>
  </div>
  </div>
</template>

<script>
    export default {
      data() {
        return {
          tableData: [{
            dname: '2016-05-02',
            dtype: '王小虎',
            dadress: '上海市普陀区金沙江路 1518 弄'
          }]
        }
      },
      methods: {
        applyresource(row){
          let id = row.id
          this.$http.post('http://127.0.0.1:8091/resouceApply/insertResourceApply',
            {id:id
            }
            ,{emulateJSON: true}).then((response) => {
              debugger
              let re = response.body
            if(re.flag == "success"){
              alert("申请成功")

            }else if (re.flag == "fail"){
              alert("申请失败")
            }
            alert(re.message);
          });
        },

        sharetypeformatter(row, column) {
          debugger
          let sharetype = row.sharetype
          if(sharetype == 1){
            return "内部无条件共享"
          }else if (sharetype == 2){
            return "内部有条件共享"
          }else if(sharetype == 3){
            return "对外开发共享"
          }
          return "异常"
        },

        sharestyleformatter(row, column) {
          let sharestyle = row.sharestyle
          if(sharestyle == 1){
            return "API服务"
          }
          return "异常"
        },
        publishformatter(row, column){
          debugger
          let isPublish = row.isPublish
          if(isPublish == 0){
            return "未发布"
          }else if(isPublish == 1){
            return "已发布"
          }
          return "异常"
        }

       },
      created() {
        this.$http.post('http://127.0.0.1:8091/dataResourceinfo/listAllResourceinfo',
          {
          }
          ,{emulateJSON: true}).then((response) => {
          // if(response.bodyText = "success"){
          this.tableData = response.body
        });
      }
    }
</script>

<style type="text/css">
  .align-center{
    margin:0 auto;      /* 居中 这个是必须的，，其它的属性非必须 */
    width:1000px;        /* 给个宽度 顶到浏览器的两边就看不出居中效果了 */
    background:white;     /* 背景色 */
    text-align:center;  /* 文字等内容居中 */
  }
</style>
